
<?php
include("db/connect.php");
include("prename.php");
$delete="delete from cart where orderid=0";
$sqlquerydelete=mysql_query($delete);
$selectproduct="SELECT * FROM product ORDER BY pro_name ASC";
$selectcustomer="select * from customer where cus_id='".$_POST["temp"]."'";
$queryproduct=mysql_query($selectproduct);
$querycustomer=mysql_query($selectcustomer);
$resultcustomer=mysql_fetch_array($querycustomer);
?>

<script>
	function submitPro(){
	//console.log($("#fromInsert_Add_Pro").serialize()+"&cus_id="+$("#cus_id").val());
	if($("#pro_color").val()=="xx"){alert("กรุณาเลือกสี");}
	if($("#qty").val()>=1&&$("#pro_color").val()!="xx"){
	
	$.ajax({
			type:"POST",
			url:"shoppingcart2.php",
			data:$("#fromInsert_Add_Pro").serialize()+"&cus_id="+$("#cus_id").val(),
			success:function(msg){
		console.log(msg);
	if(msg!=1)
	{$("#spantest").html(msg);selectcart();}
	else 
	alert("มีรายการเดิมที่ยังไม่เสร็จสมบูรณ์");
	
	}
			});//ajax
	}
	else{
		alert("จำนวนไม่ถูกต้อง");
		}
	}//function submit   
	function dltcart(PID,mode){
	if(window.confirm("ท่านต้องการลบใช่หรือไม่")){
	$.ajax({
	url:"dltcart.php",
	data:"PID="+PID+"&mode="+mode,
	type:"POST",
	success:function(msg){
	alert(msg);
	if(mode=="all"){ajaxlist();}else{selectcart();}
	}
	});}
	}

	function selectcart(){
	$.ajax({
	url:"shoppingcart3.php",
	success:function(msg){
	$("#spantest").html(msg);
	}
	});
	}
	function agreecart(){
	$.ajax({
	url:"agreecart.php",
	type:"POST",
	data:"cus_id="+$("#cus_id").val(),
	success:function(msg){
		
	if(msg!=1)
	{$("#spantest").html(msg);selectcart();}
	else 
	alert("มีรายการเดิมที่ยังไม่เสร็จสมบูรณ์");
	
	}
	});
	}
</script>

<style type="text/css">
#fromInsert_Add_Pro p {
	text-align: center;
	font-size: 36px;
}
</style>


<form id="fromInsert_Add_Pro" name="fromInsert_Add_Pro" method="post" action="Javascript:submitPro();">
  <p>ข้อมูลการสั่งซื้อสินค้า</p>
 
  <table width="528" border="0">
    <tr>
      <td>ชื่อลูกค้า</td>
      <td>
      <input type="hidden" name="cus_id" id="cus_id" disabled="disabled" value="<?php echo $resultcustomer["cus_id"]?>" />
      <input type="text" name="cus_name" id="cus_name" disabled="disabled" value="<?php echo (prename($resultcustomer["cus_title"])."".$resultcustomer["cus_name"])." ".$resultcustomer["cus_lastname"]?>" /></td>
    </tr>
    <tr>
      <td width="178">ชื่อสินค้า</td>
      <td width="340"><label for="select3"></label>
        <select name="PID" id="PID">
        <?php
        while($resultproduct=mysql_fetch_array($queryproduct)){
			?>
            <option value="<?php echo $resultproduct["pro_id"]?>"><?php echo $resultproduct["pro_name"]?></option>
			<?php
			}
		?>
        
      </select></td>
    </tr>
    <tr>
    <td>เลือกสี</td>
    <td><label for="select"></label>
      <select name="pro_color" id="pro_color">
        <option value="xx">กรุณาเลือกสี</option>
        <option value="00">แดง</option>
        <option value="01">แดงเม็ดมะขาม</option>
        <option value="02">น้ำเงิน</option>
        <option value="03">เหลือง</option>
        <option value="04">เขียว</option>
        <option value="05">เทา</option>
        <option value="06">ขาว</option>
        <option value="07">ส้ม</option>
        <option value="08">น้ำตาลอิฐ</option>
      </select></td>
    
    
    </tr>
    <tr>
      <td>จำนวน</td>
      <td >
      <label for="textfield"></label>
      <input name="qty" type="number"  id="qty" min="1" max="99999999" />
    </tr>
  </table>
  <p>
    <input type="submit" name="button3" id="button3" value="เพิ่มรายการ" />
    <input type="button" name="btnagree" id="btnagree" value="ยืนยัน" onclick="Javascript:agreecart();" />
    <input type="button" name="button2" id="button2" value="ยกเลิก"  onclick="Javascript:dltcart('','all');" />
  </p>
  <p>&nbsp;</p>
</form>
<div id="spantest"></div>

